import { CoolController, BaseController, CoolUrlTag, TagTypes } from '@cool-midway/core';
import { CoolFile } from '@cool-midway/file';
import { Body, Context, Inject, Post } from '@midwayjs/core';
import { WXService } from '../../service/wx';

/**
 * 公共接口
 */
@CoolUrlTag({ key: TagTypes.IGNORE_TOKEN, value: [''] })
@CoolController()
export class CommonController extends BaseController {
    @Inject()
    ctx: Context;
    
    @Inject()
    file: CoolFile;

    @Inject()
    wxService: WXService;

    /**
     * COS临时签名
     */
    @Post('/cosToken', { summary: 'COS临时签名' })
    async cosToken() {
        return this.ok(await this.file.upload(this.ctx), '获取成功');
    }

    /**
     * 获取手机号
     * @param code 微信code
     */
    @Post('/getPhoneNumber', { summary: '获取手机号' })
    async getPhoneNumber(@Body() params: { code: string }) {
        return this.ok(await this.wxService.getPhoneNumber(params.code), '获取成功');
    }
}
